# Test MySQL Connection Script
Write-Host "Testing MySQL connections..." -ForegroundColor Green

# Common passwords to try
$passwords = @("", "root", "123456", "root123", "password", "admin", "mysql")

# Test each password
foreach ($password in $passwords) {
    Write-Host "Testing password: '$password'" -ForegroundColor Yellow
    
    try {
        # Try to connect using PowerShell's Test-NetConnection first
        $connection = Test-NetConnection -ComputerName localhost -Port 3306 -InformationLevel Quiet
        
        if ($connection) {
            Write-Host "Port 3306 is accessible" -ForegroundColor Green
        } else {
            Write-Host "Port 3306 is not accessible" -ForegroundColor Red
            break
        }
        
        # Try to connect with mysql command if available
        $mysqlCmd = Get-Command mysql -ErrorAction SilentlyContinue
        if ($mysqlCmd) {
            if ($password -eq "") {
                $result = mysql -u root -e "SELECT 1;" 2>&1
            } else {
                $result = mysql -u root -p$password -e "SELECT 1;" 2>&1
            }
            
            if ($LASTEXITCODE -eq 0) {
                Write-Host "SUCCESS! Password is: '$password'" -ForegroundColor Green
                Write-Host "You can now connect with:" -ForegroundColor Cyan
                Write-Host "Username: root" -ForegroundColor White
                Write-Host "Password: $password" -ForegroundColor White
                break
            } else {
                Write-Host "Failed with password: '$password'" -ForegroundColor Red
            }
        } else {
            Write-Host "MySQL client not found in PATH" -ForegroundColor Red
            break
        }
    } catch {
        Write-Host "Error testing password '$password': $($_.Exception.Message)" -ForegroundColor Red
    }
}

Write-Host "Connection test completed!" -ForegroundColor Green
